﻿Imports System.IO
Imports IniFile
Public Class Skin
    Public Shared UseBackgroundImage As String = "1"
    Public Shared BackgroundImagePath As String = "background.jpg"
    Public Shared ChatRichBoxForeColor As String = "White"
    Public Shared ChatRichBoxBackColor As String = "Black"
    Public Shared MainFormForeColor As String = "White"
    Public Shared MainFormBackColor As String = "Black"
    Public Shared UserBoxForeColor As String = "White"
    Public Shared UserBoxBackColor As String = "Black"
    Public Shared InputTextBoxForeColor As String = "White"
    Public Shared InputTextBoxBackColor As String = "Black"
    Public Shared LoginLogoutButBackColor As String = "Black"
    Public Shared SwitchButBackColor As String = "Black"
    Public Shared ExitButBackColor As String = "Black"
    Public Shared SendButBackColor As String = "Black"
    Public Shared NewsButBackColor As String = "Black"

    Public Shared IncomingUserNameColor As String = "Yellow"
    Public Shared IncomingNormalTextColor As String = "White"
    Public Shared IncomingAdminTextColor As String = "CornflowerBlue"

    Public Shared OutgoingUserNameColor As String = "Aqua"
    Public Shared OutgoingNormalTextColor As String = "White"

    Public Shared WhisperColor As String = "Lime"
    Public Shared EmoteColor As String = "DarkGray"

    Public Shared SystemColor As String = "Coral"
    Public Shared ErrorColor As String = "Red"
    Public Shared InfoColor As String = "PowderBlue"

    Public Shared DateColor As String = "LightGray"

    Public Shared Sub LoadSkin(ByVal SkinToLoad As String)
        Try
            ParseSkin(SkinToLoad)
            '''''''''''''''''''''''''''''''''''
            MainForm.SuspendLayout()
            If UseBackgroundImage = "1" Then
                Dim bgimg As IO.FileInfo = New FileInfo(BackgroundImagePath)
                If bgimg.Exists Then
                    'MainForm.BackgroundImageLayout = ImageLayout.Stretch
                    MainForm.BackgroundImage = System.Drawing.Image.FromFile(BackgroundImagePath, True)
                Else
                    TextHandling.QueueMessage("", "The background image file specified in " & SkinToLoad & ".ini could not be found. Reverting to default background.", "Error")
                    MainForm.BackColor = Drawing.Color.FromName(MainFormBackColor)
                End If
            Else
                MainForm.BackColor = Drawing.Color.FromName(MainFormBackColor)
            End If
            MainForm.ChatRichBox.ForeColor = Drawing.Color.FromName(ChatRichBoxForeColor)
            MainForm.ChatRichBox.BackColor = Drawing.Color.FromName(ChatRichBoxBackColor)
            MainForm.ForeColor = Drawing.Color.FromName(MainFormForeColor)
            MainForm.UserBox.BackColor = Drawing.Color.FromName(UserBoxBackColor)
            MainForm.UserBox.ForeColor = Drawing.Color.FromName(UserBoxForeColor)
            MainForm.InputTextBox.BackColor = Drawing.Color.FromName(InputTextBoxBackColor)
            MainForm.InputTextBox.ForeColor = Drawing.Color.FromName(InputTextBoxForeColor)
            MainForm.LoginLogoutBut.BackColor = Drawing.Color.FromName(LoginLogoutButBackColor)
            MainForm.SwitchBut.BackColor = Drawing.Color.FromName(SwitchButBackColor)
            MainForm.ExitBut.BackColor = Drawing.Color.FromName(ExitButBackColor)
            MainForm.SendBut.BackColor = Drawing.Color.FromName(SendButBackColor)
            MainForm.NewsBut.BackColor = Drawing.Color.FromName(NewsButBackColor)
            MainForm.ResumeLayout(True)
        Catch ex As Exception
            Console.WriteLine("LOAD SKIN FUNCTION ERROR: " + ErrorToString())
        End Try
    End Sub

    Public Shared Sub CreateSkin(ByVal Skin As String)
        Try
            Dim SettingsFile As New IniFile.IniFile("skins\" & Skin & ".ini", True)
            SettingsFile.AddSection("Settings")
            SettingsFile.AddKey("UseBackgroundImage", UseBackgroundImage, "Settings")
            SettingsFile.AddKey("BackgroundImagePath", BackgroundImagePath, "Settings")
            SettingsFile.AddKey("ChatRichBoxForeColor", ChatRichBoxForeColor, "Settings")
            SettingsFile.AddKey("ChatRichBoxBackColor", ChatRichBoxBackColor, "Settings")
            SettingsFile.AddKey("MainFormForeColor", MainFormForeColor, "Settings")
            SettingsFile.AddKey("MainFormBackColor", MainFormBackColor, "Settings")
            SettingsFile.AddKey("UserBoxForeColor", UserBoxForeColor, "Settings")
            SettingsFile.AddKey("UserBoxBackColor", UserBoxBackColor, "Settings")
            SettingsFile.AddKey("InputTextBoxForeColor", InputTextBoxForeColor, "Settings")
            SettingsFile.AddKey("InputTextBoxBackColor", InputTextBoxBackColor, "Settings")
            SettingsFile.AddKey("LoginLogoutButBackColor", LoginLogoutButBackColor, "Settings")
            SettingsFile.AddKey("SwitchButBackColor", SwitchButBackColor, "Settings")
            SettingsFile.AddKey("ExitButBackColor", ExitButBackColor, "Settings")
            SettingsFile.AddKey("SendButBackColor", SendButBackColor, "Settings")
            SettingsFile.AddKey("NewsButBackColor", NewsButBackColor, "Settings")
            SettingsFile.AddKey("IncomingUserNameColor", IncomingUserNameColor, "Settings")
            SettingsFile.AddKey("IncomingNormalTextColor", IncomingNormalTextColor, "Settings")
            SettingsFile.AddKey("IncomingAdminTextColor", IncomingAdminTextColor, "Settings")
            SettingsFile.AddKey("OutgoingUserNameColor", OutgoingUserNameColor, "Settings")
            SettingsFile.AddKey("OutgoingNormalTextColor", OutgoingNormalTextColor, "Settings")
            SettingsFile.AddKey("WhisperColor", WhisperColor, "Settings")
            SettingsFile.AddKey("EmoteColor", EmoteColor, "Settings")
            SettingsFile.AddKey("SystemColor", SystemColor, "Settings")
            SettingsFile.AddKey("ErrorColor", ErrorColor, "Settings")
            SettingsFile.AddKey("InfoColor", InfoColor, "Settings")
            SettingsFile.AddKey("DateColor", DateColor, "Settings")

            SettingsFile.Save("skins\" & Skin & ".ini")
        Catch ex As Exception
            Console.WriteLine("CREATE SKIN FUNCTION ERROR: " + ErrorToString())
        End Try
    End Sub

    Public Shared Sub ParseSkin(ByVal Skin As String)
        Try
            Dim SkinFile As FileInfo = New FileInfo("skins\" & Skin & ".ini")
            If SkinFile.Exists Then
                Dim SettingsFile As New IniFile.IniFile("skins\" & Skin & ".ini", True)
                UseBackgroundImage = SettingsFile.GetValue("Settings", "UseBackgroundImage")
                BackgroundImagePath = SettingsFile.GetValue("Settings", "BackgroundImagePath")
                ChatRichBoxForeColor = SettingsFile.GetValue("Settings", "ChatRichBoxForeColor")
                ChatRichBoxBackColor = SettingsFile.GetValue("Settings", "ChatRichBoxBackColor")
                MainFormForeColor = SettingsFile.GetValue("Settings", "MainFormForeColor")
                MainFormBackColor = SettingsFile.GetValue("Settings", "MainFormBackColor")
                UserBoxForeColor = SettingsFile.GetValue("Settings", "UserBoxForeColor")
                UserBoxBackColor = SettingsFile.GetValue("Settings", "UserBoxBackColor")
                InputTextBoxForeColor = SettingsFile.GetValue("Settings", "InputTextBoxForeColor")
                InputTextBoxBackColor = SettingsFile.GetValue("Settings", "InputTextBoxBackColor")
                LoginLogoutButBackColor = SettingsFile.GetValue("Settings", "LoginLogoutButBackColor")
                SwitchButBackColor = SettingsFile.GetValue("Settings", "SwitchButBackColor")
                ExitButBackColor = SettingsFile.GetValue("Settings", "ExitButBackColor")
                SendButBackColor = SettingsFile.GetValue("Settings", "SendButBackColor")
                NewsButBackColor = SettingsFile.GetValue("Settings", "NewsButBackColor")
                IncomingUserNameColor = SettingsFile.GetValue("Settings", "IncomingUserNameColor")
                IncomingNormalTextColor = SettingsFile.GetValue("Settings", "IncomingNormalTextColor")
                IncomingAdminTextColor = SettingsFile.GetValue("Settings", "IncomingAdminTextColor")
                OutgoingUserNameColor = SettingsFile.GetValue("Settings", "OutgoingUserNameColor")
                OutgoingNormalTextColor = SettingsFile.GetValue("Settings", "OutgoingNormalTextColor")
                WhisperColor = SettingsFile.GetValue("Settings", "WhisperColor")
                EmoteColor = SettingsFile.GetValue("Settings", "EmoteColor")
                SystemColor = SettingsFile.GetValue("Settings", "SystemColor")
                ErrorColor = SettingsFile.GetValue("Settings", "ErrorColor")
                InfoColor = SettingsFile.GetValue("Settings", "InfoColor")
                DateColor = SettingsFile.GetValue("Settings", "DateColor")

                TextHandling.QueueMessage("", "Loaded skin 'skins\" & Skin & ".ini'", "System")
            Else
                TextHandling.QueueMessage("", "Skin file 'skins\" & Skin & ".ini' could not be found.", "Error")
            End If
        Catch ex As Exception
            Console.WriteLine("PARSE SKIN FUNCTION ERROR: " + ErrorToString())
        End Try
    End Sub
End Class